package com.bajie.bjlisten.controller;


import com.bajie.bjlisten.api.EBookControllerApi;
import com.bajie.bjlisten.entity.response.EBookResult;
import com.bajie.bjlisten.entity.response.EBookShelfResult;
import com.bajie.bjlisten.sevice.BjChaptersService;
import com.bajie.bjlisten.sevice.EBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/ebooks")
public class EBookController implements EBookControllerApi {

    @Autowired
    EBookService eBookService;

    @Autowired
    BjChaptersService bjChaptersService;

    /**
     * 删除书架
     * @param userId
     * @param ebookId
     * @return
     */
    @GetMapping("/del/{userId}/{ebookId}")
    public EBookShelfResult deleteByEbookIdAndUserId(@PathVariable(name = "userId") String userId, @PathVariable(name = "ebookId") String ebookId) {
        return eBookService.deleteByEbookIdAndUserId(userId, ebookId);
    }

    /**
     * 放入书架
     * @param userId
     * @param ebookId
     * @return
     */
    @Override
    @PostMapping("/putIntoBookShelf")
    public EBookShelfResult putIntoBookShelf(@RequestParam("userId") String userId, @RequestParam("ebookId") String ebookId) {
        return eBookService.putIntoBookShelf(userId, ebookId);
    }

    /**
     * 根据用户查询书架的小说信息
     * @param userId
     * @param offset
     * @param limit
     * @return
     */
    @PostMapping("/findBookShelfsByUserId")
    public EBookResult findBookShelfsByUserId(@RequestParam("userId") String userId,@RequestParam("offset") Integer offset, @RequestParam("limit") Integer limit){
        return eBookService.findBookShelfsByUserId(userId, offset, limit);
    }


        /**
         * 猜你喜欢
         */
    @PostMapping("/guess")
    public EBookResult findAllGuess(@RequestParam("userId") String userId, @RequestParam("offset") Integer offset, @RequestParam("limit") Integer limit){
        return eBookService.findAllGuess(userId, offset, limit);
    }


    /**
     * 八戒热推：跟最新排行功能重复，取前10本内
     * @param userId
     * @param offset
     * @param limit
     * @return
     */
    @PostMapping("/findPop")
    public EBookResult findAllByPop(@RequestParam("userId") String userId, @RequestParam("offset") Integer offset, @RequestParam("limit") Integer limit){
        return eBookService.findAllByPop(userId, offset, limit);
    }

    /**
     * 连载更新
     * @param userId
     * @param offset
     * @param limit
     * @return
     */
    @PostMapping("/findUpdate")
    public EBookResult findBookByupdateTime(@RequestParam("userId") String userId,@RequestParam("offset") Integer offset, @RequestParam("limit") Integer limit){
        return eBookService.findBookByupdateTime(userId, offset, limit);
    }

    /**
     * 最新排行，，跟八戒热推功能重复了，取10本以后的书籍
     * app传输offset和limit参数
     *
     *
     */
    @PostMapping("/findNewSort")
    public EBookResult findNewSort(@RequestParam("userId") String userId,@RequestParam("offset") Integer offset,@RequestParam("limit") Integer limit){
        return eBookService.findAllByPop(userId, offset, limit);
    }

    /**
     * 根据小说Id查询小说详情
     * @param userId
     * @param ebookId
     * @return
     */
    @PostMapping("/findByBookId")
    public EBookResult findByBookId(@RequestParam("userId") String userId,@RequestParam("ebookId") String ebookId){
        eBookService.addPop(ebookId);
        return eBookService.findByBookId(userId, ebookId);
    }


    /**
     * 根据小说ID查询目录章节
     * @param ebookId
     * @return
     */
    @GetMapping("/findChapterByEBookId/{ebookId}")
    public EBookShelfResult findChapterByEBookId(@PathVariable(name = "ebookId") String ebookId){
        return eBookService.findChapterByEBookId(ebookId);
    }


    /**
     * 同类推荐
     * 根据分类ID随机查询5本小说表小说详情
     * @param categoryId
     * @param offset
     * @param limit
     * @return
     */
    @PostMapping("/findCategoryByRandBookId")
    public EBookResult findCategoryByRandBookId(@RequestParam("categoryId") String categoryId,@RequestParam("offset") Integer offset,@RequestParam("limit") Integer limit){
        return eBookService.findCategoryByRandBookId(categoryId, offset, limit);
    }


    /*

    @Override
    @GetMapping("/getEBook")
    public EBookResult getEBook(){
        return eBookService.getEBook();
    }

    @Override
    @GetMapping("/getChapters/{ebookId}")
    public List getChapters(@PathVariable(name = "ebookId") String eBookId) {
        return eBookService.getChapters(eBookId);
    }

    @Override
    @GetMapping("/getContent/{chapterId}")
    public JSONObject getContent(@PathVariable(name = "chapterId") String chapterId) {

        return eBookService.getContent(chapterId);
    }

    @Override
    @GetMapping("/getChapterIdAndChapterName/{ebookId}")
    public Map<String, Object> getChapterIdAndChapterName(@PathVariable(name = "ebookId") String eBookId) {
        return eBookService.getChapterIdAndChapterName(eBookId);
    }

    @Override
    @GetMapping("/getEBookContent")
    public Map<String,Object> getEBookContent(String eBookId) {
        return eBookService.getEbookContent(eBookId);
    }

    @Override
    @GetMapping("/getRandomNovels/{num}")
    public List getRandomNovels(@PathVariable(name = "num") Integer num) {
        return eBookService.getRandomNovels(num);
    }

    @Override
    @GetMapping("/getBjHotNovels/{bjNum}")
    public List getBjHotNovels(@PathVariable(name = "bjNum") Integer bjNum) {
        return eBookService.getBjHotNovels(bjNum);
    }


*/


}
